package com.scenic.rd_android.ui;

import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.PopupMenu;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;

import com.nova.scenic.projectlibs.util.debug.MyLog;
import com.scenic.rd_android.R;

public class TestActionBar extends AppCompatActivity {

    MyLog log = new MyLog("TestActionBar");
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test_action_bar);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        ActionBar actionbar = getSupportActionBar();
        actionbar.setHomeAsUpIndicator(R.drawable.ic_menu);
        actionbar.setDisplayHomeAsUpEnabled(true);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        log.info("onCreateOptionsMenu " + menu);
        getMenuInflater().inflate(R.menu.menu_test_actionbar,menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        log.info("onOptionsItemSelected " + item);
        if(item.getTitle().equals( "A")){
            PopupMenu popup = new PopupMenu(TestActionBar.this,findViewById(R.id.menu_filter));
            log.info("popupMenu " + popup + findViewById(R.id.menu_filter));

            popup.getMenuInflater().inflate(R.menu.menu_test_actionbar_filter_task, popup.getMenu());
            popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    log.info("onMenuItemClick " + item);
                    return false;
                }
            });
            popup.show();
        }

        return super.onOptionsItemSelected(item);
    }
}
